<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>录入配送订单</title>
    <link rel="stylesheet" href="../../layui-v2.6.8/layui/css/layui.css">
    <script type="text/javascript" src="../../layui-v2.6.8/layui/layui.js"></script>
</head>
<body>
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">寄件人信息</label>
        <div class="layui-input-block">
            <select id="ajid" name="ajid" lay-verify="required" lay-filter="j">
                <option value="">请选择</option>
            </select>
            <a href="AddSendInfor.html" class="layui-btn layui-btn-danger layui-btn-xs">添加寄件人信息</a>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">收件人信息</label>
        <div class="layui-input-block">
            <select id="asid" name="asid" lay-verify="required" lay-filter="s">
                <option value="">请选择</option>
            </select>
            <a href="AddRecipientInfor.html" class="layui-btn layui-btn-danger layui-btn-xs">添加收件人信息</a>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">货物类型</label>
        <div class="layui-input-block">
            <select name="kind" lay-verify="required">
                <option value="衣物">衣物</option>
                <option value="日用品">日用品</option>
                <option value="电子产品">电子产品</option>
                <option value="易碎品">易碎品</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">单价</label>
        <div class="layui-input-block">
            <input type="text" name="unitprice" required  lay-verify="required" placeholder="kg/元" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">货重</label>
        <div class="layui-input-block">
            <input type="text" name="pweight" required  lay-verify="required" placeholder="kg" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea name="tip" placeholder="请输您要备注的信息" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(['form','layer'],function(){
        var form = layui.form;
        var $ = layui.$;
        var layer = layui.layer;

        //订单提交
        form.on('submit(formDemo)', function(data){
            $.ajax({
                url:'http://localhost:8080/addorder',
                async: true,
                type : 'get',
                dataType: 'json',
                data: data.field,
                success: function (data) {
                    if (data.code === 0) {
                        layer.msg("添加成功", {icon: 6});
                        setTimeout(function () {
                                location.reload();//刷新页面
                            },
                            1000
                        );
                    } else {
                        layer.msg("添加失败", {icon: 5});
                    }
                }
            });
            return false;
        });

        //寄件人信息下拉菜单
        form.on('select(j)',function(data){
            $.ajax({
                type: 'post',
                url: 'http://localhost:8080/searchAddress',
                dataType: 'json',
                async: false,
                cache: false,
                success: function (data){
                    $.each(data.data,function (index,item){
                        $('#ajid').append(new Option(item.acontact,item.aid))
                     });
                     layui.form.render("select");
                }
            })
        });

        //收件人信息下拉菜单
        form.on('select(s)',function(data){
            $.ajax({
                type: 'post',
                url: 'http://localhost:8080/searchAddress',
                dataType: 'json',
                async: false,
                cache: false,
                success: function (data){
                    $.each(data.data,function (index,item){
                        $('#asid').append(new Option(item.acontact,item.aid));
                    });
                    layui.form.render("select");
                }
            })
        });
    });
</script>

</body>
</html>